#include <iostream>
#include <vector>
#include "thread.hpp"

using namespace ThreadModule;


const int num = 10;
void print(int &cnt)
{
    while (cnt)
    {
        std::cout << "hello I am myself thread, cnt: " << cnt-- << std::endl;
        sleep(1);
    }
}
int main()
{
    //创建一批线程
    std::vector<Thread<int >> threads;
    for(int i = 0;i < num;i++)
    {
        std::string name = "thread-" + std::to_string(i+1);
        threads.emplace_back(print,num,name);
    }
    //启动一批线程
    for(auto& thread:threads)
    {
        thread.Start();
    }
    //等待一批线程
    for(auto& thread:threads)
    {
        thread.Join();
        std::cout<<"wait thread name: "<<thread.name()<<std::endl;
    }
    //
    // int n = 10;
    // Thread<int> t1(print, 10);
    // t1.Start();
    // std::cout << "name: " << t1.name() << std::endl;
    // t1.Join();
    return 0;
}